﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.DynamicData.ModelProviders;

namespace Mpu.NHibernateDataModelProvider.AssociationProviders
{
    public class NHibernateManyToOneAssociationProvider : AssociationProvider
    {
        public NHibernateManyToOneAssociationProvider(ColumnProvider columnProvider, NHibernate.Mapping.Property property, NHibernate.Mapping.Column column)
            : base()
        {
            this.Direction = AssociationDirection.ManyToOne;
            this.FromColumn = columnProvider;
            this.IsPrimaryKeyInThisTable = false;
            this.ToTable = columnProvider.Table.DataModel.Tables.First(t => t.Name == "Publishers");

            this.ForeignKeyNames = property.Value.ColumnIterator.Select(c => c.Text).ToList().AsReadOnly(); ;
        }
    }
}
